home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Essential Home & Business Collection
/
The Essential Home & Business Collection.iso
/
27
/
3
/
5
/
HP22D5.ZIP
/
EXTERN
/
WITEM.C
< prev
next >
Wrap
Text File
|
1991-04-16
|
1KB
|
72 lines
#include "extern.h"
/*
** This routine searches a string of items for a particular item and returns
** its item position (or 0 it it wasn't there). For example:
**
** whichItem("orange,apple,fruit","apple") -- returns 2
**
** To call this routine from HyperPAD:
**
** put whichItem(page field 1,"fruit") into w;
**
** To use a different item delimiter, pass it as the third parameter:
**
** whichItem("orange|apple|fruit","apple","|") -- returns 2
**
*/
whichitem(NumArgs,hList,hItem,hDelimiter)
int NumArgs;
HANDLE hList,hItem,hDelimiter;
{
PTR p,item,s;
int c = 1;
int rep,rc;
char d;
if (NumArgs < 2 || NumArgs > 3) return(STOP);
/* p = pointer to item list */
p = deref(hList);
/* item = pointer to item */
item = deref(hItem);
/* d = delimiter (use a comma if delimiter is not specified) */
d = (NumArgs == 3) ? *deref(hDelimiter) : ',';
while (1) {
s = p;
while (*p && (*p != d)) p++;
if (rep = *p) *p = '\0';
rc = strcmpi(s,item);
if (rep) *p = d;
if (!rc) break;
if (rep) p++;
else {
c = 0;
break;
}
c++;
}
ReturnValue(itoh(c));
return(STOP);
}
POOL pascal Pool[] = {
{ "whichItem",
whichitem,
0,
FUNCTION},
{ NULL, /* NULLs signify the end of the table */
NULL,
0,
0} };